package com.syqc.monitor.ui.alarm

import android.widget.TextView
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager.OnPageChangeListener
import com.syqc.adapter.IFragmentPAdapter
import com.syqc.comlib.base.BaseBarActivity
import com.syqc.comlib.custom.MToolbar
import com.syqc.comlib.rx.filterFast
import com.syqc.comlib.utils.ToolbarHelper
import com.syqc.comlib.utils.startActivityTo
import com.syqc.monitor.R
import com.syqc.monitor.databinding.ActivityHandleAlarmBinding
import com.syqc.monitor.ui.realalarm.SubAlarmActivity2
import com.syqc.utils.Keys
import com.syqc.utils.ToolsUtil

/**
 *@author joker
 *@time   2023/12/29 8:32
 *@desc
 */
class AlarmsHandleActivity :
    BaseBarActivity<ActivityHandleAlarmBinding>(ActivityHandleAlarmBinding::inflate) {
    private val mTypeFragment by lazy { AlarmTypeFragment() }

    override fun initView() {
        ToolbarHelper.setToolbar(
            this,
            R.string.title_other_handle_alarm,
            R.string.title_action_subscribe,
            object : MToolbar.IToolbarCallback {
                override fun actionOnClick(action: TextView) {
                    if (ToolsUtil.isFastClick()) return
                    startActivityTo<SubAlarmActivity2>(this@AlarmsHandleActivity) {
                        putParcelableArrayListExtra(Keys.INTENT_DATA, mTypeFragment.getAlarms())
                    }
                }
            }
        )

        val fragments = ArrayList<Fragment>()
        fragments.add(mTypeFragment)
        fragments.add(CarAlarmsFragment())
        binding.nsVpAlarm.adapter = IFragmentPAdapter(supportFragmentManager, fragments)

        binding.nsVpAlarm.addOnPageChangeListener(object :OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                binding.rdbType.isChecked = position==0
                binding.rdbCar.isChecked = position==1
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })

    }

    override fun setListener() {
        binding.rdbType.filterFast {
            binding.rdbType.isChecked = true
            binding.nsVpAlarm.currentItem = 0
        }

        binding.rdbCar.filterFast {
            binding.rdbCar.isChecked = true
            binding.nsVpAlarm.currentItem = 1
        }
    }
}